package com.example.myapplication6.bean;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;

public class showdescActivity extends Activity implements View.OnClickListener {
    private static final String TAG = "showdescActivity";
    private TextView deal_title;
    private TextView website;
    private TextView deal_desc;
    private TextView price;
    private TextView value;
    private TextView rebate;
    private TextView sales_num;
    private TextView shop_addr;
    private TextView shop_name;
    private TextView shop_tel;
    private TextView start_time;
    private TextView end_time;
    private TextView last_time;
    private Button back_bt;
    private Button collect_bt;
    private ImageView image;
    private meituan mei;
    private Button buy;
    private Button fav;
    private String addr;
    private String name;
    private String tel;

    public showdescActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(1);
        this.setContentView(2449540647);
        Bundle bundle = this.getIntent().getExtras();
        this.mei = (meituan)bundle.getSerializable("mei");
        System.out.println(this.mei.getUrl());
        this.deal_title = (TextView)this.findViewById(2131230725);
        this.deal_title.setText(this.mei.getDeal_title());
        this.website = (TextView)this.findViewById(2131230724);
        this.website.setText("【" + this.mei.getWebsite() + "】");
        this.deal_desc = (TextView)this.findViewById(2131230734);
        this.deal_desc.setText(this.mei.getDeal_desc());
        this.image = (ImageView)this.findViewById(2131230733);
        this.image.setImageBitmap(this.getBitmap(this.mei.getDeal_img()));
        this.start_time = (TextView)this.findViewById(2131230735);
        this.start_time.setText(this.formatTime(this.mei.getStart_time()));
        this.end_time = (TextView)this.findViewById(2131230736);
        this.end_time.setText(this.formatTime(this.mei.getEnd_time()));
        this.last_time = (TextView)this.findViewById(2131230737);
        this.last_time.setText(this.getTime(System.currentTimeMillis() / 1000L, this.mei.getEnd_time()));
        this.price = (TextView)this.findViewById(2131230726);
        this.price.setText("现价 : ¥ " + this.mei.getPrice());
        this.value = (TextView)this.findViewById(2131230727);
        this.value.setText("原价 : ¥ " + this.mei.getValue());
        this.value.getPaint().setFlags(16);
        this.rebate = (TextView)this.findViewById(2131230728);
        this.rebate.setText("折扣 : " + this.mei.getRebate());
        this.sales_num = (TextView)this.findViewById(2131230738);
        this.sales_num.setText("已经有     " + this.mei.getSales_num() + "  人购买");
        if (this.mei.getShop_addr() == null) {
            this.addr = "未知";
        } else {
            this.addr = this.mei.getShop_addr();
        }

        this.shop_addr = (TextView)this.findViewById(2131230739);
        this.shop_addr.setText("地址 : " + this.addr);
        if (this.mei.getShop_name() == null) {
            this.name = "未知";
        } else {
            this.name = this.mei.getShop_name();
        }

        this.shop_name = (TextView)this.findViewById(2131230740);
        this.shop_name.setText("商家名称 : " + this.name);
        if (this.mei.getShop_tel() == null) {
            this.tel = "未知";
        } else {
            this.tel = this.mei.getShop_tel();
        }

        this.shop_tel = (TextView)this.findViewById(2131230741);
        this.shop_tel.setText("商家电话 : " + this.tel);
        this.fav = (Button)this.findViewById(2131230743);
        this.fav.setOnClickListener(this);
        this.back_bt = (Button)this.findViewById(2131230730);
        this.back_bt.setOnClickListener(this);
        this.collect_bt = (Button)this.findViewById(2131230744);
        this.collect_bt.setOnClickListener(this);
        this.buy = (Button)this.findViewById(2131230742);
        this.buy.setOnClickListener(this);
    }

    public void onClick(View v) {
        if (v == this.fav) {
            try {
                DataIUDS data = new DataIUDS(this);
                data.save(this.mei);
                Toast.makeText(this, "收藏添加成功", 1).show();
            } catch (Exception var4) {
                Log.e("showdescActivity", var4.toString());
                Toast.makeText(this, "收藏添加失败，请重新添加", 1).show();
            }
        } else if (v == this.back_bt) {
            this.finish();
        } else if (v == this.collect_bt) {
            Intent intent = new Intent();
            intent.setAction("com.kang.mycollectActivity");
            this.startActivity(intent);
        } else if (v == this.buy) {
            String url = this.mei.getUrl();
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse(url));
            this.startActivity(intent);
        }

    }

    private String formatTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(time * 1000L);
        String data = sdf.format(date);
        return data;
    }

    private String getTime(long start_time, long end_time) {
        long last_time = end_time - start_time;
        long day = last_time / 86400L;
        long hour = last_time / 3600L - day * 24L;
        String str = "还有" + day + "天" + hour + "小时";
        return str;
    }

    private Bitmap getBitmap(String path) {
        try {
            URL url = new URL(path);
            HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
            InputStream input = httpConn.getInputStream();
            Bitmap image = BitmapFactory.decodeStream(input);
            return image;
        } catch (Exception var6) {
            Log.i("showdescActivity", var6.toString());
            return null;
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = this.getMenuInflater();
        inflater.inflate(2131165184, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 2131230730:
                this.finish();
                break;
            case 2131230731:
                Intent intent2 = new Intent();
                intent2.setClass(this, tuangouActivity.class);
                this.startActivity(intent2);
                break;
            case 2131230752:
                Intent intent = new Intent();
                intent.setAction("com.kang.mycollectActivity");
                this.startActivity(intent);
                break;
            case 2131230753:
                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.setTitle(2131034127);
                final LinearLayout author = (LinearLayout)this.getLayoutInflater().inflate(2130903040, (ViewGroup)null);
                dialog.setView(author);
                dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        EditText edit_suggest = (EditText)author.findViewById(2131230723);
                        String suggest = edit_suggest.getText().toString();

                        try {
                            Intent emailIntent = new Intent("android.intent.action.SEND");
                            emailIntent.setType("plain/text");
                            emailIntent.putExtra("android.intent.extra.EMAIL", "liuzihan@126.com");
                            emailIntent.putExtra("android.intent.extra.SUBJECT", "处理订单意见");
                            emailIntent.putExtra("android.intent.extra.TEXT", suggest);
                            showdescActivity.this.startActivity(Intent.createChooser(emailIntent, "订单发送中...."));
                        } catch (Exception var6) {
                            Log.e("showdescActivity", var6.toString());
                            Toast.makeText(showdescActivity.this, "请设置您手机里的收货地址", 1).show();
                        }

                    }
                });
                dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
            case 2131230754:
                System.out.println("exit");
                Intent intent1 = new Intent("android.intent.action.MAIN");
                intent1.addCategory("android.intent.category.HOME");
                intent1.setFlags(268435456);
                this.startActivity(intent1);
        }

        return true;
    }
}
